package net.nshc.kwkim.mycalc.buttonlistener;

import net.nshc.kwkim.mycalc.*;
import net.nshc.kwkim.mycalc.util.*;
import android.app.*;
import android.content.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

public class ButtonClickListener implements OnClickListener {
    
    protected Context context = null;
    protected EditText editTextInput = null;
    
    public ButtonClickListener(Context context) {
        this.context = context;
        this.editTextInput
            = (EditText)((Activity)context).findViewById(R.id.input);
    }
    
    public void onClick(View v) {
        ImageButton buttonClicked = (ImageButton)v;
        appendString(editTextInput, buttonClicked.getContentDescription().toString());
    }
    
    protected void appendString(EditText editText, String str) {
        StringBuilder textFromEditText = new StringBuilder(ButtonContentAnalyzer.hasStingErrorMessage(editText.getText().toString().trim()));
        
        if (textFromEditText != null) {
            textFromEditText.append(str);
            editText.setText(textFromEditText);
        }
    }
}